//
//  CDBManager.h
//  Fiverun
//
//  Created by yilong.zhang on 11-8-17.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AppConfig.h"
#import "CUser.h"
#import "CDraft.h"
#import <sqlite3.h>

#define DB_Name     @"Delicious"

@class AppConfig;
@class CUser;
@class CProduct;
@class CDraft;
@class CCommentary;

@interface CKey : NSObject

@property (nonatomic, retain) NSString  *m_Name;
@property (nonatomic, retain) NSString  *m_Type;    //ld, @, f, b
@property (nonatomic, retain) id        m_Value;
@property (nonatomic, assign) int       m_nType;    //1(integer(32)), 2(float), 3(text), 4(blob), 5(NULL)
@property (nonatomic, assign) BOOL      m_bPrimary;

-(id)initWithType:(int)type Length:(int)length Name:(NSString*)name Primary:(BOOL)primary;
-(id)initWithType:(int)type Value:(id)value Name:(NSString*)name;

@end

@interface CDBManager : NSObject 
{
	sqlite3		*m_pDB;
	NSString	*m_strDBName;
	BOOL		m_bIsDBOpened;
}

@property sqlite3 *m_pDB;

+(CDBManager*)ScheduledShareInstance;
+(void)DestoryShareInstance;

-(id)initWithDBName:(NSString*)dbname;
-(void)CreateDB;

//打开制定数据库
-(BOOL)OpenDatabase;

//new
-(int)CreateTable:(NSString *)tablename Keys:(NSArray *)keys;
-(int)RemoveTable:(NSString *)tablename;
-(int)ClearTable:(NSString *)tablename;
-(int)GetRecordTotal:(NSString *)tablename Condition:(NSString*)condition Key:(NSString*)key;
-(NSArray*)QueryRecordsFromCursor:(NSString*)tablename Keys:(NSArray*)keys Offset:(int)offset Limit:(int)limit Column:(int)column Condition:(NSString*)condition;
-(int)InsertNewRecordToTable:(NSString*)tablename Keys:(NSArray*)keys;
-(int)UpdateRecordInfo:(NSString*)tablename Keys:(NSArray*)keys Condition:(NSString*)condition;
-(int)DeleteRecord:(NSString*)tablename Condition:(NSString*)condition;

@end
